const path=require('path');
const fs=require('fs');
const express=require('express');
const app=express();
const bodyParser=require('body-parser');
app.use(bodyParser.urlencoded({extended:false,limit:'10mb'}));
app.use(bodyParser.json({limit:'10mb'}));
//设置静态路径
app.use("/fileUpload",express.static(path.join(__dirname,"./fileUpload")));
app.use("/h1802file",express.static(path.join(__dirname,"./h1802file")));


app.use((req,resp,next)=>{
  resp.setHeader("Access-Control-Allow-Orogin","*");
  resp.setHeader("Access-Control-Allow-Methods","GET,POST,PUT,DELETE,OPTIONS");
  resp.setHeader("Access-Control-Allow-Header","Content-Type");
  next();
});

//加载路由
app.use("/Stu_info",require("./routes/Stu_infoRouter"));
app.use("/Score_info",require("./routes/Score_infoRouter"));
app.use("/Exam_info",require("./routes/Exam_infoRouter"));
app.use("/Softeem_web",require("./routes/Softeem_webRouter"));

app.get("/",(req,resp)=>{
  resp.send("http://www.softeem.xin"+(new Date()).toLocaleString());
});

app.get("/update",(req,resp)=>{
  var jsonStr=fs.readFileSync(path.join(__dirname,"./config/update.json")).toString();
  var jsonObj=JSON.parse(jsonStr);
  resp.json(jsonObj);
});

app.listen(80,function(){
  console.log("服务器启动成功，端口80");
});

module.exports=app;